package com.bbva.tasks;

import com.microstrategy.utils.StringUtils;
import com.microstrategy.utils.log.Level;
import com.microstrategy.web.app.tasks.BeanTaskRequestContext;
import com.microstrategy.web.app.tasks.ReportDataServiceTask;
import com.microstrategy.web.beans.ReportBean;
import com.microstrategy.web.beans.WebBeanException;
import com.microstrategy.web.tasks.TaskException;
import com.microstrategy.web.tasks.TaskParameterMetadata;

public class AsyncReportExec extends ReportDataServiceTask {

	 protected void registerParameterMetadata(TaskParameterMetadata taskparametermetadata)
	    {
		 	super.registerParameterMetadata(taskparametermetadata);
		 	if(taskparametermetadata.getName().equals(REPORT_STYLE))
		 		reportStyle = taskparametermetadata;
	    }
	 protected void collectData(BeanTaskRequestContext bsrContext) throws TaskException
	 {
		 super.collectData(bsrContext);
		 String FUNCTION_NAME = "collectData";
		 String styleParamStr = reportStyle.getValue(bsrContext.getRequestKeys());
		 Log.logger.logp(Level.INFO, CLASS_NAME, FUNCTION_NAME, "Start Sort Report Procedure");
		 if(StringUtils.isEqual("ResultSetStatusStyle", styleParamStr))
		 {
			 ReportBean rb = (ReportBean)bsrContext.getWebBean();
			 try {
				rb.getReportInstance().setAsync(true);
			} catch (WebBeanException e) {
				e.printStackTrace();
			}
        }
      }
	private String REPORT_STYLE = "styleName";
	private TaskParameterMetadata reportStyle;
    private String CLASS_NAME = "com.bbva.tasks.CustomReportExecutionTask";
}
